1include <../std.scad>
2include <../vnf.scad>
3
4
5module test_is_vnf() {
6 assert(is_vnf([[],[]]));
7 assert(!is_vnf([]));
8 assert(is_vnf([[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]]));
9}
10test_is_vnf();
11
12
13module test_is_vnf_list() {
14 assert(is_vnf_list([]));
15 assert(!is_vnf_list([[],[]]));
16 assert(is_vnf_list([[[],[]]]));
17 assert(!is_vnf_list([[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]]));
18 assert(is_vnf_list([[[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]]]));
19}
20test_is_vnf_list();
21
22
23module test_vnf_vertices() {
24 vnf = [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]];
25 assert(vnf_vertices(vnf) == vnf[0]);
26}
27test_vnf_vertices();
28
29
30module test_vnf_faces() {
31 vnf = [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]];
32 assert(vnf_faces(vnf) == vnf[1]);
33}
34test_vnf_faces();
35
36
37module test_vnf_from_polygons() {
38 verts = [[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]];
39 faces = [[0,1,2],[0,3,1],[2,3,0],[0,1,0]]; // Last face has zero area
40 assert(vnf_merge_points(
41 vnf_from_polygons([for (face=faces) select(verts,face)])) == [verts,select(faces,0,-2)]);
42}
43test_vnf_from_polygons();
44
45
46
47module test_vnf_volume() {
48 assert_approx(vnf_volume(cube(100, center=false)), 1000000);
49 assert(approx(vnf_volume(sphere(d=100, anchor=BOT, $fn=144)) / (4/3*PI*pow(50,3)),1, eps=.001));
50}
51test_vnf_volume();
52
53
54
55module test_vnf_area(){
56 assert(approx(vnf_area(sphere(d=100, $fn=144)) / (4*PI*50*50),1, eps=1e-3));
57}
58test_vnf_area();
59
60
61module test_vnf_join() {
62 vnf1 = vnf_from_polygons([[[-1,-1,-1],[1,-1,-1],[0,1,-1]]]);
63 vnf2 = vnf_from_polygons([[[1,1,1],[-1,1,1],[0,1,-1]]]);
64 assert(vnf_join([vnf1,vnf2]) == [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[1,1,1],[-1,1,1],[0,1,-1]],[[0,1,2],[3,4,5]]]);
65}
66test_vnf_join();
67
68
69module test_vnf_triangulate() {
70 vnf = [[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]],[[0,1,2,3]]];
71 assert(vnf_triangulate(vnf) == [[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]], [[0,1,2],[2,3,0]]]);
72}
73test_vnf_triangulate();
74
75
76module test_vnf_vertex_array() {
77 vnf1 = vnf_vertex_array(
78 points=[for (h=[0:100:100]) [[100,-50,h],[-100,-50,h],[0,100,h]]],
79 col_wrap=true, caps=true
80 );
81 vnf2 = vnf_vertex_array(
82 points=[for (h=[0:100:100]) [[100,-50,h],[-100,-50,h],[0,100,h]]],
83 col_wrap=true, caps=true, style="alt"
84 );
85 vnf3 = vnf_vertex_array(
86 points=[for (h=[0:100:100]) [[100,-50,h],[-100,-50,h],[0,100,h]]],
87 col_wrap=true, caps=true, style="quincunx"
88 );
89 assert(vnf1 == [[[100,-50,0],[-100,-50,0],[0,100,0],[100,-50,100],[-100,-50,100],[0,100,100]],[[2,1,0],[3,4,5],[0,4,3],[0,1,4],[1,5,4],[1,2,5],[2,3,5],[2,0,3]]]);
90 assert(vnf2 == [[[100,-50,0],[-100,-50,0],[0,100,0],[100,-50,100],[-100,-50,100],[0,100,100]],[[2,1,0],[3,4,5],[0,1,3],[3,1,4],[1,2,4],[4,2,5],[2,0,5],[5,0,3]]]);
91 assert(vnf3 == [[[100,-50,0],[-100,-50,0],[0,100,0],[100,-50,100],[-100,-50,100],[0,100,100],[0,-50,50],[-50,25,50],[50,25,50]],[[2,1,0],[3,4,5],[0,6,3],[3,6,4],[4,6,1],[1,6,0],[1,7,4],[4,7,5],[5,7,2],[2,7,1],[2,8,5],[5,8,3],[3,8,0],[0,8,2]]]);
92}
93test_vnf_vertex_array();
94
95
96// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap